import redis


class RedisOn():
    def __init__(self):
        self.conn = redis.Redis(host='localhost', port=6379, db=1)

    # 字符串操作(存储)
    def set_str(self, key, value):
        for i in value:
            return self.conn.sadd(key, i)


    # 字符串操作(读取)
    def set_get(self, key):
        value = self.conn.get(key)
        if value:
            list = []
            for i in value:
                list.append(str(i, encoding='utf8'))
                return list


    def str_delete(self, key):
        return self.conn.delete(key)

    # 存哈希类型
    def hash_set(self, name, mapping):
        return self.conn.hset(name, mapping)



    def hget_keys(self, key):
        return self.conn.hgetall(key)




    def hget_key(self, key, key1):
        return self.conn.hget(key, key1)


red = RedisOn()
